package com.wl.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/cookie")
public class CookieServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 1. 创建Cookie
        Cookie c = new Cookie("username","123456");
        Cookie p = new Cookie("userpwd","666");
        // 2.设置路径
        c.setPath("/");
        p.setPath("/");
        // 3.设置有效期，秒单位 (默认是session会话浏览器关闭即会话结束)
        c.setMaxAge(60*60*24*365);
        // 4.设置给resp
        resp.addCookie(c);
        resp.addCookie(p);
    }
}
